package main

import (
	"gitee.com/moyrn/sa/_example/moyrn/function"
	"gitee.com/moyrn/sa/command"
	"gitee.com/moyrn/sa/engine"
	"gitee.com/moyrn/sa/store"
	"gitee.com/moyrn/sa/store/models"
	"log"
)

var (
	domain   = "http://test.test.cn"
	startUrl = []string{
		"/url1",
		"/url2",
	}
	adapters = []engine.Adapter{
		{ParserFunction: "parserFunction", Adapter: function.Home},
	}
)

func main() {
	sqLiteStore, err := command.NewStore()
	if err != nil {
		log.Panic(err)
	}
	if err := command.InitEngine(sqLiteStore, "test.log"); err != nil {
		log.Panic(err)
	}

	command.RegisterAdapters(adapters)

	seeds := make([]models.Task, 0, len(startUrl))
	for _, u := range startUrl {
		seeds = append(seeds, models.Task{Url: domain + u, UniqueKey: store.UniqueIndex(domain, u), ParserFunction: "parserFunction", Status: models.Unload})
	}

	command.Run(models.Task{
		Url:            domain + startUrl[0],
		UniqueKey:      store.UniqueIndex(domain, startUrl[0]),
		ParserFunction: "parserFunction",
		Status:         models.Unload,
	}, models.Task{
		Url:            domain + startUrl[1],
		UniqueKey:      store.UniqueIndex(domain, startUrl[1]),
		ParserFunction: "parserFunction",
		Status:         models.Unload,
	})
}
